<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name=" apple-mobile-web-app-capable" />
    <!-- 隐藏状态栏  -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/details.css">
</head>

<body>
    <header>
        <div class="wrapper clearfix">
            <div class="login_fl fl">
                <a href="javascript:history.back()" class="login_icon"><img src="img/srh_icon.png" alt=""></a>
            </div>
            <h1>重置登录密码</h1>
        </div>
    </header>
    <article class="mod-forgot p10 login_mod">
        <input type="text" class="phone getPhoneNum" placeholder="手机号/昵称" value="" id="phoneNum" readonly="">
        <input type="text" class="vcode" placeholder="验证码">
        <a class="gain_vcode gain_vcode1" href="javascript:void(0)" id="captchaBtn">获取</a>
        <input type="password" class="phone psw1" placeholder="密码">
        <input type="password" class="phone psw2" placeholder="再次输入密码">
        <input type="submit" class="next_step" value="重置密码" onclick="toResetPsw()">
    </article>
</body>
<script src="js/jquery-1.11.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/constants.js"></script>
<script src="js/common.js"></script>
<script>
var phoneNum = getParameterByName('phoneNum');
var isUserLogin = getParameterByName('isUserLogin');

var regex = /^1[3|4|5|8|7][0-9]\d{4,8}$/;

var captchaBtn = $('#captchaBtn');

var remainTime = 60;

/*******************************验证码获取****************************/
function captchaClick() {
    // var phoneNum = $('#phoneNum').val();
    // 判断是否登录过 isUserLogin==0表示没有登录过
    if (isUserLogin == 0) {
        var phoneNum = $('#phoneNum').val();
    } else {
        var phoneNum = getParameterByName('phoneNum');
    }
    // 充值登录密码验证码
    var urlCaptcha = server_host + '/update/sendSmsToUserResetPasswd.do?phoneNum=' + phoneNum;
    if (regex.test(phoneNum)) {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: urlCaptcha,
            success: function(data) {
                console.log(data);
                if (data.code == 0) {
                    captchaBtn.addClass('act');
                    captchaBtn.unbind('click');
                    captchaBtn.html(remainTime);
                    var timer = setInterval(function() {
                        remainTime--;
                        captchaBtn.html(remainTime);
                        if (remainTime == 0) {
                            clearInterval(timer);
                            captchaBtn.removeClass('act');
                            captchaBtn.bind('click', captchaClick);
                            captchaBtn.html('获取');
                            remainTime = 60;
                        }
                    }, 1000);
                } else {
                    alert(data.msg);
                }
            }
        });
    } else {
        alert('请输入正确的手机号码！');
    }
}

$(document).ready(function() {

    $('#phoneNum').val(phoneNum);
    // 验证码获取
    captchaBtn.bind('click', captchaClick);
    // 判断是否传入电话号码
    getPhoneNum();
});

function getPhoneNum() {
    // 判断是否登录过 isUserLogin==0表示没有登录过
    if (isUserLogin == 0) {
        var phoneNum = $('#phoneNum').val();
        $('.getPhoneNum').removeAttr('readonly');
    } else {
        var phoneNum = getParameterByName('phoneNum');
    }
}
/*******************************充值密码提交****************************/
function toResetPsw() {
    var vNum = $('.vcode').val();
    var passwd = $('.psw1').val();
    // 判断是否登录过 isUserLogin==0表示没有登录过

    if ($('.psw1').val() == $('.psw2').val()) {

        if (isUserLogin == 0) {
            var phoneNum = $('#phoneNum').val();
            var urlSubmit = server_host + '/update/updateUpdatePasswd.do?phoneNum=' + phoneNum + '&vNum=' + vNum + '&passwd=' + passwd;
        } else {
            var phoneNum = getParameterByName('phoneNum');
            var urlSubmit = server_host + '/userweb/update/updateUpdatePasswd.do?phoneNum=' + phoneNum + '&vNum=' + vNum + '&passwd=' + passwd;
        }

        if ($('.vcode').val() == '') {
            alert('请输入验证码');
        } else {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: urlSubmit,
                success: function(data) {
                    console.log(data);
                    if (data.isSuccess) {
                        alert(data.msg);
                        // alert(11);
                        // 跳到注册页
                        location.href = 'login.html?fr=pc';
                    } else {
                        alert(data.msg);
                        // alert(22);
                    }
                }
            });
        }

    } else {
        alert('两次密码不一致,请重新输入。')
    }
}
$(document).ready(function() {
    captchaBtn.bind('click', captchaClick);
});
</script>
</body>
<span style="display:none;"><script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1255764485'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s95.cnzz.com/z_stat.php%3Fid%3D1255764485%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));</script></span>
<script>
    _maq.push(['_setMaq', 're_password']);
</script>

</html>
